
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/17/2013 15:41:54
-- Generated from EDMX file: C:\Users\rrodriguez\Desktop\MVP_PRO\MVP_PRO\DBLayer\DataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [PointSales];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CategoryProduct]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Products] DROP CONSTRAINT [FK_CategoryProduct];
GO
IF OBJECT_ID(N'[dbo].[FK_SaleSaleDetail]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SaleDetails] DROP CONSTRAINT [FK_SaleSaleDetail];
GO
IF OBJECT_ID(N'[dbo].[FK_SaleDetailProduct]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SaleDetails] DROP CONSTRAINT [FK_SaleDetailProduct];
GO
IF OBJECT_ID(N'[dbo].[FK_DiscountSystemUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Discounts] DROP CONSTRAINT [FK_DiscountSystemUser];
GO
IF OBJECT_ID(N'[dbo].[FK_SaleDiscount]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Discounts] DROP CONSTRAINT [FK_SaleDiscount];
GO
IF OBJECT_ID(N'[dbo].[FK_SaleCard]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TypePaymets_Card] DROP CONSTRAINT [FK_SaleCard];
GO
IF OBJECT_ID(N'[dbo].[FK_FranChiseSale]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sales] DROP CONSTRAINT [FK_FranChiseSale];
GO
IF OBJECT_ID(N'[dbo].[FK_SystemUserSale]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sales] DROP CONSTRAINT [FK_SystemUserSale];
GO
IF OBJECT_ID(N'[dbo].[FK_FranChisePrinter]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Printers] DROP CONSTRAINT [FK_FranChisePrinter];
GO
IF OBJECT_ID(N'[dbo].[FK_SalePesoMxn]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TypePaymets_PesoMxn] DROP CONSTRAINT [FK_SalePesoMxn];
GO
IF OBJECT_ID(N'[dbo].[FK_SaleDollar]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TypePaymets_Dollar] DROP CONSTRAINT [FK_SaleDollar];
GO
IF OBJECT_ID(N'[dbo].[FK_HomeDeliverySale]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sales] DROP CONSTRAINT [FK_HomeDeliverySale];
GO
IF OBJECT_ID(N'[dbo].[FK_Card_inherits_TypePaymet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TypePaymets_Card] DROP CONSTRAINT [FK_Card_inherits_TypePaymet];
GO
IF OBJECT_ID(N'[dbo].[FK_FranChise_inherits_Company]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Companies_FranChise] DROP CONSTRAINT [FK_FranChise_inherits_Company];
GO
IF OBJECT_ID(N'[dbo].[FK_PesoMxn_inherits_TypePaymet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TypePaymets_PesoMxn] DROP CONSTRAINT [FK_PesoMxn_inherits_TypePaymet];
GO
IF OBJECT_ID(N'[dbo].[FK_Dollar_inherits_TypePaymet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TypePaymets_Dollar] DROP CONSTRAINT [FK_Dollar_inherits_TypePaymet];
GO
IF OBJECT_ID(N'[dbo].[FK_Client_inherits_Company]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Companies_Client] DROP CONSTRAINT [FK_Client_inherits_Company];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[SystemUsers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SystemUsers];
GO
IF OBJECT_ID(N'[dbo].[Products]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Products];
GO
IF OBJECT_ID(N'[dbo].[ProductCategorys]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProductCategorys];
GO
IF OBJECT_ID(N'[dbo].[Companies]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Companies];
GO
IF OBJECT_ID(N'[dbo].[Messages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Messages];
GO
IF OBJECT_ID(N'[dbo].[FTPServers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FTPServers];
GO
IF OBJECT_ID(N'[dbo].[Printers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Printers];
GO
IF OBJECT_ID(N'[dbo].[Sales]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sales];
GO
IF OBJECT_ID(N'[dbo].[SaleDetails]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SaleDetails];
GO
IF OBJECT_ID(N'[dbo].[Discounts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Discounts];
GO
IF OBJECT_ID(N'[dbo].[TypePaymets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TypePaymets];
GO
IF OBJECT_ID(N'[dbo].[UpdateElement]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UpdateElement];
GO
IF OBJECT_ID(N'[dbo].[HomeDeliveries]', 'U') IS NOT NULL
    DROP TABLE [dbo].[HomeDeliveries];
GO
IF OBJECT_ID(N'[dbo].[DataBaseVersionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DataBaseVersionSet];
GO
IF OBJECT_ID(N'[dbo].[TypePaymets_Card]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TypePaymets_Card];
GO
IF OBJECT_ID(N'[dbo].[Companies_FranChise]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Companies_FranChise];
GO
IF OBJECT_ID(N'[dbo].[TypePaymets_PesoMxn]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TypePaymets_PesoMxn];
GO
IF OBJECT_ID(N'[dbo].[TypePaymets_Dollar]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TypePaymets_Dollar];
GO
IF OBJECT_ID(N'[dbo].[Companies_Client]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Companies_Client];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'SystemUsers'
CREATE TABLE [dbo].[SystemUsers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [LoginID] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Logins] smallint  NULL,
    [Rights] smallint  NOT NULL
);
GO

-- Creating table 'Products'
CREATE TABLE [dbo].[Products] (
    [Id] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Price] float  NOT NULL,
    [ProductCategoryId] int  NOT NULL,
    [Public] bit  NOT NULL
);
GO

-- Creating table 'ProductCategorys'
CREATE TABLE [dbo].[ProductCategorys] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Companies'
CREATE TABLE [dbo].[Companies] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [RFC] nvarchar(max)  NULL,
    [Addres1] nvarchar(max)  NOT NULL,
    [Addres2] nvarchar(max)  NOT NULL,
    [CodeZip] smallint  NOT NULL,
    [State] nvarchar(max)  NOT NULL,
    [City] nvarchar(max)  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Messages'
CREATE TABLE [dbo].[Messages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Message1] nvarchar(max)  NULL,
    [Message2] nvarchar(max)  NULL,
    [Message3] nvarchar(max)  NULL,
    [Message4] nvarchar(max)  NULL,
    [Message5] nvarchar(max)  NULL
);
GO

-- Creating table 'FTPServers'
CREATE TABLE [dbo].[FTPServers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [HostName] nvarchar(max)  NOT NULL,
    [Port] smallint  NOT NULL
);
GO

-- Creating table 'Printers'
CREATE TABLE [dbo].[Printers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Cashier] nvarchar(max)  NOT NULL,
    [Kitchen] nvarchar(max)  NOT NULL,
    [FranChiseId] int  NOT NULL
);
GO

-- Creating table 'Sales'
CREATE TABLE [dbo].[Sales] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Date] datetime  NOT NULL,
    [FranChiseId] int  NOT NULL,
    [SystemUserId] int  NOT NULL,
    [RateExchange] float  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Folio] int  NOT NULL,
    [Invoiced] bit  NULL,
    [Type] tinyint  NOT NULL,
    [PercentageTax] float  NULL,
    [PhoneNumber] bigint  NULL
);
GO

-- Creating table 'SaleDetails'
CREATE TABLE [dbo].[SaleDetails] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SaleId] int  NOT NULL,
    [Cuantity] smallint  NOT NULL,
    [UnitPrice] float  NOT NULL,
    [ProductId] int  NOT NULL
);
GO

-- Creating table 'Discounts'
CREATE TABLE [dbo].[Discounts] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SystemUserId] int  NOT NULL,
    [Note] nvarchar(max)  NOT NULL,
    [Percentage] float  NOT NULL,
    [Sale_Id] int  NOT NULL
);
GO

-- Creating table 'TypePaymets'
CREATE TABLE [dbo].[TypePaymets] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Amount] float  NOT NULL
);
GO

-- Creating table 'UpdateElement'
CREATE TABLE [dbo].[UpdateElement] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Version] datetime  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Update] bit  NOT NULL
);
GO

-- Creating table 'HomeDeliveries'
CREATE TABLE [dbo].[HomeDeliveries] (
    [PhoneNumber] bigint  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Addres] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'DataBaseVersionSet'
CREATE TABLE [dbo].[DataBaseVersionSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Date] datetime  NOT NULL,
    [Version] int  NOT NULL
);
GO

-- Creating table 'TypePaymets_Card'
CREATE TABLE [dbo].[TypePaymets_Card] (
    [Id] int  NOT NULL,
    [Sale_Id] int  NOT NULL
);
GO

-- Creating table 'Companies_FranChise'
CREATE TABLE [dbo].[Companies_FranChise] (
    [StartDate] datetime  NOT NULL,
    [Tax] float  NOT NULL,
    [RateExChange] float  NOT NULL,
    [Contact] nvarchar(max)  NULL,
    [Alias] nvarchar(max)  NOT NULL,
    [Code] smallint  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'TypePaymets_PesoMxn'
CREATE TABLE [dbo].[TypePaymets_PesoMxn] (
    [Id] int  NOT NULL,
    [Sale_Id] int  NOT NULL
);
GO

-- Creating table 'TypePaymets_Dollar'
CREATE TABLE [dbo].[TypePaymets_Dollar] (
    [Id] int  NOT NULL,
    [Sale_Id] int  NOT NULL
);
GO

-- Creating table 'Companies_Client'
CREATE TABLE [dbo].[Companies_Client] (
    [Email] nvarchar(max)  NULL,
    [CelPhone] nvarchar(max)  NULL,
    [Public] bit  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'SystemUsers'
ALTER TABLE [dbo].[SystemUsers]
ADD CONSTRAINT [PK_SystemUsers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [PK_Products]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProductCategorys'
ALTER TABLE [dbo].[ProductCategorys]
ADD CONSTRAINT [PK_ProductCategorys]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Companies'
ALTER TABLE [dbo].[Companies]
ADD CONSTRAINT [PK_Companies]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [PK_Messages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FTPServers'
ALTER TABLE [dbo].[FTPServers]
ADD CONSTRAINT [PK_FTPServers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Printers'
ALTER TABLE [dbo].[Printers]
ADD CONSTRAINT [PK_Printers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Sales'
ALTER TABLE [dbo].[Sales]
ADD CONSTRAINT [PK_Sales]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SaleDetails'
ALTER TABLE [dbo].[SaleDetails]
ADD CONSTRAINT [PK_SaleDetails]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Discounts'
ALTER TABLE [dbo].[Discounts]
ADD CONSTRAINT [PK_Discounts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TypePaymets'
ALTER TABLE [dbo].[TypePaymets]
ADD CONSTRAINT [PK_TypePaymets]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UpdateElement'
ALTER TABLE [dbo].[UpdateElement]
ADD CONSTRAINT [PK_UpdateElement]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [PhoneNumber] in table 'HomeDeliveries'
ALTER TABLE [dbo].[HomeDeliveries]
ADD CONSTRAINT [PK_HomeDeliveries]
    PRIMARY KEY CLUSTERED ([PhoneNumber] ASC);
GO

-- Creating primary key on [Id] in table 'DataBaseVersionSet'
ALTER TABLE [dbo].[DataBaseVersionSet]
ADD CONSTRAINT [PK_DataBaseVersionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TypePaymets_Card'
ALTER TABLE [dbo].[TypePaymets_Card]
ADD CONSTRAINT [PK_TypePaymets_Card]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Companies_FranChise'
ALTER TABLE [dbo].[Companies_FranChise]
ADD CONSTRAINT [PK_Companies_FranChise]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TypePaymets_PesoMxn'
ALTER TABLE [dbo].[TypePaymets_PesoMxn]
ADD CONSTRAINT [PK_TypePaymets_PesoMxn]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TypePaymets_Dollar'
ALTER TABLE [dbo].[TypePaymets_Dollar]
ADD CONSTRAINT [PK_TypePaymets_Dollar]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Companies_Client'
ALTER TABLE [dbo].[Companies_Client]
ADD CONSTRAINT [PK_Companies_Client]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ProductCategoryId] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [FK_CategoryProduct]
    FOREIGN KEY ([ProductCategoryId])
    REFERENCES [dbo].[ProductCategorys]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryProduct'
CREATE INDEX [IX_FK_CategoryProduct]
ON [dbo].[Products]
    ([ProductCategoryId]);
GO

-- Creating foreign key on [SaleId] in table 'SaleDetails'
ALTER TABLE [dbo].[SaleDetails]
ADD CONSTRAINT [FK_SaleSaleDetail]
    FOREIGN KEY ([SaleId])
    REFERENCES [dbo].[Sales]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SaleSaleDetail'
CREATE INDEX [IX_FK_SaleSaleDetail]
ON [dbo].[SaleDetails]
    ([SaleId]);
GO

-- Creating foreign key on [ProductId] in table 'SaleDetails'
ALTER TABLE [dbo].[SaleDetails]
ADD CONSTRAINT [FK_SaleDetailProduct]
    FOREIGN KEY ([ProductId])
    REFERENCES [dbo].[Products]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SaleDetailProduct'
CREATE INDEX [IX_FK_SaleDetailProduct]
ON [dbo].[SaleDetails]
    ([ProductId]);
GO

-- Creating foreign key on [SystemUserId] in table 'Discounts'
ALTER TABLE [dbo].[Discounts]
ADD CONSTRAINT [FK_DiscountSystemUser]
    FOREIGN KEY ([SystemUserId])
    REFERENCES [dbo].[SystemUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiscountSystemUser'
CREATE INDEX [IX_FK_DiscountSystemUser]
ON [dbo].[Discounts]
    ([SystemUserId]);
GO

-- Creating foreign key on [Sale_Id] in table 'Discounts'
ALTER TABLE [dbo].[Discounts]
ADD CONSTRAINT [FK_SaleDiscount]
    FOREIGN KEY ([Sale_Id])
    REFERENCES [dbo].[Sales]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SaleDiscount'
CREATE INDEX [IX_FK_SaleDiscount]
ON [dbo].[Discounts]
    ([Sale_Id]);
GO

-- Creating foreign key on [Sale_Id] in table 'TypePaymets_Card'
ALTER TABLE [dbo].[TypePaymets_Card]
ADD CONSTRAINT [FK_SaleCard]
    FOREIGN KEY ([Sale_Id])
    REFERENCES [dbo].[Sales]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SaleCard'
CREATE INDEX [IX_FK_SaleCard]
ON [dbo].[TypePaymets_Card]
    ([Sale_Id]);
GO

-- Creating foreign key on [FranChiseId] in table 'Sales'
ALTER TABLE [dbo].[Sales]
ADD CONSTRAINT [FK_FranChiseSale]
    FOREIGN KEY ([FranChiseId])
    REFERENCES [dbo].[Companies_FranChise]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FranChiseSale'
CREATE INDEX [IX_FK_FranChiseSale]
ON [dbo].[Sales]
    ([FranChiseId]);
GO

-- Creating foreign key on [SystemUserId] in table 'Sales'
ALTER TABLE [dbo].[Sales]
ADD CONSTRAINT [FK_SystemUserSale]
    FOREIGN KEY ([SystemUserId])
    REFERENCES [dbo].[SystemUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SystemUserSale'
CREATE INDEX [IX_FK_SystemUserSale]
ON [dbo].[Sales]
    ([SystemUserId]);
GO

-- Creating foreign key on [FranChiseId] in table 'Printers'
ALTER TABLE [dbo].[Printers]
ADD CONSTRAINT [FK_FranChisePrinter]
    FOREIGN KEY ([FranChiseId])
    REFERENCES [dbo].[Companies_FranChise]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FranChisePrinter'
CREATE INDEX [IX_FK_FranChisePrinter]
ON [dbo].[Printers]
    ([FranChiseId]);
GO

-- Creating foreign key on [Sale_Id] in table 'TypePaymets_PesoMxn'
ALTER TABLE [dbo].[TypePaymets_PesoMxn]
ADD CONSTRAINT [FK_SalePesoMxn]
    FOREIGN KEY ([Sale_Id])
    REFERENCES [dbo].[Sales]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SalePesoMxn'
CREATE INDEX [IX_FK_SalePesoMxn]
ON [dbo].[TypePaymets_PesoMxn]
    ([Sale_Id]);
GO

-- Creating foreign key on [Sale_Id] in table 'TypePaymets_Dollar'
ALTER TABLE [dbo].[TypePaymets_Dollar]
ADD CONSTRAINT [FK_SaleDollar]
    FOREIGN KEY ([Sale_Id])
    REFERENCES [dbo].[Sales]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SaleDollar'
CREATE INDEX [IX_FK_SaleDollar]
ON [dbo].[TypePaymets_Dollar]
    ([Sale_Id]);
GO

-- Creating foreign key on [PhoneNumber] in table 'Sales'
ALTER TABLE [dbo].[Sales]
ADD CONSTRAINT [FK_HomeDeliverySale]
    FOREIGN KEY ([PhoneNumber])
    REFERENCES [dbo].[HomeDeliveries]
        ([PhoneNumber])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HomeDeliverySale'
CREATE INDEX [IX_FK_HomeDeliverySale]
ON [dbo].[Sales]
    ([PhoneNumber]);
GO

-- Creating foreign key on [Id] in table 'TypePaymets_Card'
ALTER TABLE [dbo].[TypePaymets_Card]
ADD CONSTRAINT [FK_Card_inherits_TypePaymet]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[TypePaymets]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Companies_FranChise'
ALTER TABLE [dbo].[Companies_FranChise]
ADD CONSTRAINT [FK_FranChise_inherits_Company]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Companies]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'TypePaymets_PesoMxn'
ALTER TABLE [dbo].[TypePaymets_PesoMxn]
ADD CONSTRAINT [FK_PesoMxn_inherits_TypePaymet]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[TypePaymets]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'TypePaymets_Dollar'
ALTER TABLE [dbo].[TypePaymets_Dollar]
ADD CONSTRAINT [FK_Dollar_inherits_TypePaymet]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[TypePaymets]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Companies_Client'
ALTER TABLE [dbo].[Companies_Client]
ADD CONSTRAINT [FK_Client_inherits_Company]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Companies]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------